using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Auto.Web.Common;
using Auto.Components;

namespace BaseSystem._System
{
    public partial class SearchRoles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }
        private void InitPage()
        {
            this.UcRolesTree1.TreeInit(SessionBox.CurrentSystem, SessionBox.CurrentSystem);
        }

        protected void btnGetValue_Click(object sender, EventArgs e)
        {
            string text = string.Empty;
            string value = string.Empty;
            TreeNodeCollection tnc = this.UcRolesTree1.CheckedTreeViewNodes;
            if (tnc != null)
            {
                foreach (TreeNode trChecked in tnc)
                {
                    if (trChecked.ChildNodes.Count >= 1 && trChecked.ChildNodes[0].Value == "true")
                    {
                        text += "[" + trChecked.Parent.Text + "," + trChecked.Text + "," + (trChecked.ChildNodes[0].Checked ? Resources.Base.AllowWithGrant : Resources.Base.ForbidWithGrant)
                            + "]<BR>";

                        value += "" + trChecked.Parent.Value + "," + trChecked.Value + "," + trChecked.ChildNodes[0].Checked.ToString()
                            + "|";
                    }
                }
            }
            Jscript.AjaxRunJs(this, string.Format("SetRoleValue('{0}','{1}');", text, value.TrimEnd('|')));
        }
    }
}
